package com.nuaa.dao.transfer.impl;

import java.io.File;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.stereotype.Repository;

import com.nuaa.dao.base.impl.BaseDaoImpl;
import com.nuaa.dao.transfer.inter.SupDaoInter;
import com.nuaa.domain.change.SupplyEntity;
import com.nuaa.domain.transfer.TransSupEntity;
/**
 * @author heaven
 * 中转业务提交补充文档
 *
 */
@Repository("transSupDao")
public class SupDaoImpl extends BaseDaoImpl<TransSupEntity, Integer> implements SupDaoInter{
	@Transactional
	@Override
	public boolean delByOrderNo(String orderNo) {
		
		StringBuilder sql=new StringBuilder();
		sql.append("select * from transfer_sup where order_no = '");
		sql.append(orderNo);
		sql.append("'");
		List<TransSupEntity> list = this.search(TransSupEntity.class, sql.toString());
		if(list.size()==0)
			return false;
		TransSupEntity entity = list.get(0);
		String dir = System.getProperty("webApp.path")+"file";
		System.out.println(dir);
		if(!"".equals(entity.getDeliver_number_tb())){
			File file = new File(dir+"\\"+entity.getDeliver_number_tb());
			if(file.exists()){
				file.delete();
			}
		}
		if(!"".equals(entity.getDeliver_order_tb())){
			File file = new File(dir+"\\"+entity.getDeliver_order_tb());
			if(file.exists()){
				file.delete();
			}
		}
		if(!"".equals(entity.getOther_file())){
			File file = new File(dir+"\\"+entity.getOther_file());
			if(file.exists()){
				file.delete();
			}
		}
//		StringBuffer sql2 = new StringBuffer();
//		sql.append("delete from transfer_sup where order_no ='");
//		sql.append(orderNo);
//		sql.append("'");
		try{
			//this.update(sql2.toString());
			this.delete(entity);
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		return true;
	}
	@Override
	public void fileByName(String fileName) {
		String dir = System.getProperty("webApp.path")+"file";
		if(!"".equals(fileName)){
			File file = new File(dir+"\\"+fileName);
			if(file.exists()){
				file.delete();
			}
		}
		
	}
}
